using System;
using System.Collections.Generic;
using Random = UnityEngine.Random;

namespace Framework
{
    public static class CommonUtil
    {
        public static void Shuffle<T>(this List<T> list)
        {
            int count = list.Count;
            for (int i = 0; i < count; ++i)
            {
                int randomIndex = Random.Range(i, count);
                T current = list[i];
                list[i] = list[randomIndex];
                list[randomIndex] = current;
            }
        }

        public static string Uniform(this string value)
        {
            return value.Replace('\\', '/');
        }

        public static void SafeInvoke(this Action action)
        {
            if (action != null)
            {
                action.Invoke();
            }
        }
        
        public static void SafeInvoke<T>(this Action<T> action, T arg)
        {
            if (action != null)
            {
                action.Invoke(arg);
            }
        }
    }
}